package com.bbva.kyfb.kyfbjpatlsb.dominiotlsb;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.roo.addon.dbre.RooDbManaged;
import org.springframework.roo.addon.entity.RooEntity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;
import org.springframework.transaction.annotation.Transactional;

/**
 * The Class Tbdbzbit.
 */
@Entity
@Table(name = "TBDBZBIT",schema = "BDBZ")
@Configurable
@RooJavaBean
@RooToString
@RooEntity(identifierType = TbdbzbitPK.class, versionField = "",  persistenceUnit="persistenceUnitTLSB", table = "TBDBZBIT", schema = "BDBZ")
@PersistenceContext(unitName="persistenceUnitTLSB")
@RooDbManaged(automaticallyDelete = true)
public class Tbdbzbit {

	/** The fec recepcio. */
	@Column(name = "FEC_RECEPCIO",columnDefinition = "DATE")
    @NotNull
    @Temporal(TemporalType.DATE)
    @DateTimeFormat(style = "M-")
    private Date fecRecepcio;

	/** The hms recepcio. */
	@Column(name = "HMS_RECEPCIO",columnDefinition = "DATE")
    @NotNull
    @Temporal(TemporalType.TIME)
    @DateTimeFormat(style = "M-")
    private Date hmsRecepcio;

	/** The aud usuario. */
	@Column(name = "AUD_USUARIO",columnDefinition = "CHAR", length = 8)
    @NotNull
    private String audUsuario;

	/** The aud fmodific. */
	@Column(name = "AUD_FMODIFIC",columnDefinition = "DATE")
    @NotNull
    @Temporal(TemporalType.DATE)
    @DateTimeFormat(style = "M-")
    private Date audFmodific;

	/** The cod pid. */
	@Column(name = "COD_PID",columnDefinition = "SMALLINT")
    private Short codPid;

	/** The tim firma. */
	@Column(name = "TIM_FIRMA",columnDefinition = "TIMESTAMP")
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(style = "M-")
    private Date timFirma;

	/**
	 * Gets the fec recepcio.
	 *
	 * @return the fec recepcio
	 */
	public Date getFecRecepcio() {
        return this.fecRecepcio;
    }

	/**
	 * Sets the fec recepcio.
	 *
	 * @param fecRecepcio the new fec recepcio
	 */
	public void setFecRecepcio(Date fecRecepcio) {
        this.fecRecepcio = fecRecepcio;
    }

	/**
	 * Gets the hms recepcio.
	 *
	 * @return the hms recepcio
	 */
	public Date getHmsRecepcio() {
        return this.hmsRecepcio;
    }

	/**
	 * Sets the hms recepcio.
	 *
	 * @param hmsRecepcio the new hms recepcio
	 */
	public void setHmsRecepcio(Date hmsRecepcio) {
        this.hmsRecepcio = hmsRecepcio;
    }

	/**
	 * Gets the aud usuario.
	 *
	 * @return the aud usuario
	 */
	public String getAudUsuario() {
        return this.audUsuario;
    }

	/**
	 * Sets the aud usuario.
	 *
	 * @param audUsuario the new aud usuario
	 */
	public void setAudUsuario(String audUsuario) {
        this.audUsuario = audUsuario;
    }

	/**
	 * Gets the aud fmodific.
	 *
	 * @return the aud fmodific
	 */
	public Date getAudFmodific() {
        return this.audFmodific;
    }

	/**
	 * Sets the aud fmodific.
	 *
	 * @param audFmodific the new aud fmodific
	 */
	public void setAudFmodific(Date audFmodific) {
        this.audFmodific = audFmodific;
    }

	/**
	 * Gets the cod pid.
	 *
	 * @return the cod pid
	 */
	public Short getCodPid() {
        return this.codPid;
    }

	/**
	 * Sets the cod pid.
	 *
	 * @param codPid the new cod pid
	 */
	public void setCodPid(Short codPid) {
        this.codPid = codPid;
    }

	/**
	 * Gets the tim firma.
	 *
	 * @return the tim firma
	 */
	public Date getTimFirma() {
        return this.timFirma;
    }

	/**
	 * Sets the tim firma.
	 *
	 * @param timFirma the new tim firma
	 */
	public void setTimFirma(Date timFirma) {
        this.timFirma = timFirma;
    }

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("AudFmodific: ").append(getAudFmodific()).append(", ");
        sb.append("AudUsuario: ").append(getAudUsuario()).append(", ");
        sb.append("CodPid: ").append(getCodPid()).append(", ");
        sb.append("FecRecepcio: ").append(getFecRecepcio()).append(", ");
        sb.append("HmsRecepcio: ").append(getHmsRecepcio()).append(", ");
        sb.append("Id: ").append(getId()).append(", ");
        sb.append("TimFirma: ").append(getTimFirma());
        return sb.toString();
    }

	/** The entity manager. */
	@PersistenceContext(unitName="persistenceUnitTLSB")
    transient EntityManager entityManager;

	/** The id. */
	@EmbeddedId
    private TbdbzbitPK id;

	/**
	 * Gets the id.
	 *
	 * @return the id
	 */
	public TbdbzbitPK getId() {
        return this.id;
    }

	/**
	 * Sets the id.
	 *
	 * @param id the new id
	 */
	public void setId(TbdbzbitPK id) {
        this.id = id;
    }

	/**
	 * Persist.
	 */
	@Transactional(value="tlsb")
    public void persist() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.persist(this);
    }

	/**
	 * Removes the.
	 */
	@Transactional(value="tlsb")
    public void remove() {
        if (this.entityManager == null) this.entityManager = entityManager();
        if (this.entityManager.contains(this)) {
            this.entityManager.remove(this);
        } else {
            Tbdbzbit attached = Tbdbzbit.findTbdbzbit(this.id);
            this.entityManager.remove(attached);
        }
    }

	/**
	 * Flush.
	 */
	@Transactional(value="tlsb")
    public void flush() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.flush();
    }

	/**
	 * Clear.
	 */
	@Transactional(value="tlsb")
    public void clear() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.clear();
    }

	/**
	 * Merge.
	 *
	 * @return the tbdbzbit
	 */
	@Transactional(value="tlsb")
    public Tbdbzbit merge() {
        if (this.entityManager == null) this.entityManager = entityManager();
        Tbdbzbit merged = this.entityManager.merge(this);
        this.entityManager.flush();
        return merged;
    }

	/**
	 * Entity manager.
	 *
	 * @return the entity manager
	 */
	public static final EntityManager entityManager() {
        EntityManager em = new Tbdbzbit().entityManager;
        if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");
        return em;
    }

	
	/**
	 * Count tbdbzbits.
	 *
	 * @return the long
	 */
	@Transactional(value="tlsb")
	public static long countTbdbzbits() {
        return entityManager().createQuery("SELECT COUNT(o) FROM Tbdbzbit o", Long.class).getSingleResult();
    }

	
	/**
	 * Find all tbdbzbits.
	 *
	 * @return the list
	 */
	@Transactional(value="tlsb")
	public static List<Tbdbzbit> findAllTbdbzbits() {
        return entityManager().createQuery("SELECT o FROM Tbdbzbit o", Tbdbzbit.class).getResultList();
    }

	
	/**
	 * Find tbdbzbit.
	 *
	 * @param id the id
	 * @return the tbdbzbit
	 */
	@Transactional(value="tlsb")
	public static Tbdbzbit findTbdbzbit(TbdbzbitPK id) {
        if (id == null) return null;
        return entityManager().find(Tbdbzbit.class, id);
    }

	
	/**
	 * Find tbdbzbit entries.
	 *
	 * @param firstResult the first result
	 * @param maxResults the max results
	 * @return the list
	 */
	@Transactional(value="tlsb")
	public static List<Tbdbzbit> findTbdbzbitEntries(int firstResult, int maxResults) {
        return entityManager().createQuery("SELECT o FROM Tbdbzbit o", Tbdbzbit.class).setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
    }
}
